﻿<script src="/static/js/jquery-2.1.1.js"></script>
<script src="/static/bootstrap/js/bootstrap.js"></script>
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
<link href="/static/layui/css/layui.css" rel="stylesheet"/>
<script src="/static/layui/layui.js"></script>
<script type="text/javascript" src="/static/js/Calendar.js"></script>

<!--弹框js-->
<script src="/static/js/yii.js"></script>
<style>
    .layui-inline{margin-bottom:15px;display: inline-block}
    .layui-input-block{margin-left:0px!important;}
    .zxd_coordinate{border:1px solid silver;line-height:30px;height:30px;display: inline-block;padding:0px 10px;border-radius:3px;margin:5px;background-color: #0b6fff;color: #fff}
    .zxd_contetnt{line-height:30px;padding-right:10px!important;padding-left:10px!important;}
    .zxd_list{display: inline-block;width:100%;line-height:38px;}
    .zxd_list div{background-color:#f5f5f5;margin-bottom:15px;padding:5px 10px;border-radius:4px;display: inline-block;width:100%}
    .zxd_list span{display:inline-block;width:100%;text-align: right;font-size:12px;}
    .zxd_history{padding-right:10px!important;padding-left:10px!important;height:300px;display: block;overflow:auto;  }
    .layui-select-disabled .layui-disabled{
        color:#000000!important;
    }
    .config_img {
        height:65px;
        margin-top: 15px;
    }
    .images_del{text-align: center}
    .show_multiple{float: left;margin-left:15px;}
    #images_upload{display: inline-block;float: left;padding:0px 10px;}
    .newimg{float: left;margin-left:15px;}
    .newimg img{height:40px;}
</style>
<div class="modal-body">

    <!--layui-form-pane-->
    <form class="layui-form layui-form-pane form-horizontal" name="saveForm" action=""  >

        {if condition="$type_id eq 344"}
        <div class="layui-form-item layui-col-md12">
            <label class="layui-form-label">入库编码</label>
            <div class="input-group col-xs-9" style="float: left">
                <input type="text"  name="code" value="{$detail.code}" class="layui-input" >
            </div>
        </div>
        {/if}

        <div class="layui-form-item layui-col-md12">
            <label class="layui-form-label">汇报内容</label>
            <div class="input-group col-xs-9" style="float: left;border:1px #e6e6e6 solid;padding:10px">
                {$detail.content}
            </div>
        </div>

        <div class="layui-form-item layui-col-md12">
            <label class="layui-form-label">计划时间</label>
            <div class="input-group col-xs-9" style="float: left">
                <input type="text" name="time"  value="{$detail.time}" class="layui-input" onClick="new Calendar().show(this);">
            </div>
        </div>


        <div class="layui-form-item layui-col-md12">
            <label class="layui-form-label">汇报时间</label>
            <div class="input-group col-xs-9" style="float: left">
                <input type="text" name="end_time"  value="{$detail.end_time}" class="layui-input" onClick="new Calendar().show(this);">
            </div>
        </div>

        {if condition="count($detail['images'])>0"}
        <div class="layui-form-item layui-col-md12" style="width:100%">
            <label class="layui-form-label">*图组</label>
            <!--存储上传的图片信息-->
            <div class="layui-input-block">
                <div class="input-group">
                    <!--<div id="images_upload" ><img src="/static/images/upload.jpeg" style="width:100px;height:100px;"></div>-->
                    <div class="input-group show_multiple row">
                        {volist name="$detail['images']" id="vo1"}
                        <div class="newimg"><img src="{$vo1}" onclick="visitImg('{$vo1}');"  ><input type="hidden" name="images[]" value="{$vo1}"></div>
                        {/volist}
                    </div>
                </div>
            </div>
        </div>
        {/if}

        <div class="layui-form-item layui-col-md12">
            <label class="layui-form-label">服务单位</label>
            <div id="duty_unit" class="demo-transfer"></div>
        </div>


        <div class="layui-form-item layui-col-md12" >
            <label class="layui-form-label">备注</label>
            <div class="input-group col-xs-9"  style="float: left">
                <textarea class="layui-textarea" type="text" name="remark">{$detail.remark}</textarea>
            </div>
        </div>

        <div class="layui-form-item layui-col-md12">
            <label class="layui-form-label">操作</label>
            <div class="input-group col-xs-9" style="float: left">
                <input type="radio" name="status" value="1" title="通过" {if condition="$detail['status'] eq 1"} checked {/if} >
                <input type="radio" name="status" value="2" title="驳回" {if condition="$detail['status'] eq 2"} checked {/if}>
            </div>
        </div>


        <input type="hidden" name="type_id" value="{$type_id}">
        <input type="hidden" name="pro_id" value="{$proId}">
        <input type="hidden" name="id" value="{$detail.id}">
        <input type="hidden" name="duty_unit" value="">
    </form>

    <button style="opacity: 0" id="getData"></button>

</div>
<script>
    layui.extend({
        tinymce: '/static/tinymce/tinymce'
    });
    layui.use(['form','tinymce','laydate','transfer'], function() {
        var form = layui.form
            , layer = layui.layer;
        var tinymce = layui.tinymce;
        var transfer = layui.transfer;
        var laydate = layui.laydate;
        //责任单位
        var duty_unit = {$duty_unit};
        // //责任单位
        transfer.render({
            elem: '#duty_unit'
            ,id:'duty_unit'
            ,data: duty_unit
            ,title: ['全选', '全选']
            ,showSearch: true
            ,height:200
            ,value:{$duty_unit_k}
        }),
        // lay('.test-item1').each(function(){
        //     laydate.render({
        //         elem: this
        //         ,trigger: 'click'
        //     });
        // });

        tinymce.render({
            elem:'#content',
            height: 600,
            images_upload_handler: function (blobInfo, succFun, failFun) {
                var xhr, formData;
                var file = blobInfo.blob();//转化为易于理解的file对象
                xhr = new XMLHttpRequest();
                xhr.withCredentials = false;
                xhr.open('POST', "{:URL('/common/upload/textUpload')}");
                xhr.onload = function() {
                    var json;
                    json = JSON.parse(xhr.responseText);
                    succFun(json.path);
                };
                formData = new FormData();
                formData.append('file', file, file.name );//此处与源文档不一样
                xhr.send(formData);
            }
        },(opt, edit) => {});

        function eachvalue(data){
            var newvalue = '';
            $.each(data,function (index,value) {
                newvalue+=value.title+";";
            });
            return newvalue;
        };

        $("#getData").click(function () {
            console.log(1111);
            var duty_unit = transfer.getData('duty_unit');
            $("input[name='duty_unit']").val(JSON.stringify(duty_unit))
            console.log(duty_unit);
        })

        $("#newsave").click(function () {
            var content = tinymce.get('#content').getContent();
            var duty_unit = transfer.getData('duty_unit');
            var duty_person = transfer.getData('duty_person');
            var leader = transfer.getData('leader');

            var duty_unit_v = eachvalue(duty_unit);
            var duty_person_v = eachvalue(duty_person);
            var leader_v = eachvalue(leader);

            var data = $("form[name='layui-form']").serializeArray();
            data.push({name: "content", value: content});
            data.push({name: "duty_unit", value: duty_unit_v});
            data.push({name: "duty_person", value: duty_person_v});
            data.push({name: "leader", value: leader_v});
            $.ajax({
                type:'post',
                url:"{:URL('project/index/add')}",
                data:data,
                dataType:'JSON',
                success:function (res) {
                    if(res.code!=0){
                        layer.alert(res.msg);
                    }else{
                        window.location.href = "{:URL('project/index/index')}?library="+library;
                    }
                },
                error:function (res) {
                }
            });
        });

        layui.form.render('select');
        form.render();
    });


    var newModal = new yii.modal();
    $(".show_multiple").on("click",".images_del",function () {
        $(this).parent().remove();
    })
    //多图片上传
    $("#images_upload").click(function () {
        $(newModal.getid()).show();
        newModal.initialization({
            url: "{:URL('common/Upload/index')}",
            type: "post",
            data:{
                type:'detail',
                multiple:'multiple'
            }
        });
    });

    newModal.on("multiple",function(data){
        var images = '';
        $(newModal.getid()).find("#data-area .newimages .active img").each(function () {
            images += '<div class="newimg"><img src="'+$(this).attr('src')+'" ><input type="hidden" name="images[]" value="'+$(this).attr('src')+'"><div class="images_del" >删除</div></div>';
        })
        $(newModal.getid()).hide();
        //遮罩层隐藏
        //$('#nowMainProjectDataForm').modal('hide');
        $(".modal-backdrop").remove();
        $(newModal.getid()).find(".modal").hide();
        $(".show_multiple").append(images);
    });
    //多图上传
    layui.use(['form', 'laydate','upload'], function () {
        var form = layui.form;


    });

    function visitImg(imgUrl) {
        layer.photos({
            photos : {
                "title" : "",
                "id" : 123,
                "start" : 0,
                "data" : [
                    {
                        "alt" : "",
                        "pid" : 666,
                        "src" : imgUrl,
                        "thumb" : ""
                    } ]
            }
        });
    }





</script>